//
// SignalHandler.cpp
//
// $Id: //poco/1.4/Foundation/src/SignalHandler.cpp#2 $
//
// Library: Foundation
// Package: Threading
// Module:  SignalHandler
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


#include "Poco/SignalHandler.h"
#include "Poco/Format.h"

#if defined(POCO_OS_FAMILY_UNIX) && !defined(POCO_VXWORKS)


#include "Poco/Thread.h"
#include "Poco/Exception.h"
#include <cstdlib>
#include <signal.h>


namespace Poco {


SignalHandler::SignalHandler()
{

}


SignalHandler::~SignalHandler()
{
}


// void SignalHandler::throwSignalException(int sig)
// {
// 	switch (sig)
// 	{
// 	case SIGILL:
// 		throw SignalException("Illegal instruction");
// 	case SIGBUS:
// 		throw SignalException("Bus error");
// 	case SIGSEGV:
// 		throw SignalException("Segmentation violation");
// 	case SIGSYS:
// 		throw SignalException("Invalid system call");
// 	default:
// 		throw SignalException(format("%x",sig));
// 	}
// }


void SignalHandler::install(unsigned int sig,SignalHandler_SA_Handler callback)
{
	struct sigaction sa;
	sa.sa_handler = callback;	
	sa.sa_flags   = 0;
	sigemptyset(&sa.sa_mask);
	sigaction(sig,  &sa, 0);
}


void SignalHandler::install(unsigned int sig,unsigned int flags, SignalHandler_SA_Sigaction callback)
{
	struct sigaction sa;
	sa.sa_sigaction = callback;	
	sa.sa_flags   = flags & SA_SIGINFO;
	sigemptyset(&sa.sa_mask);
	sigaction(sig,  &sa, 0);
}


} // namespace Poco


#endif // POCO_OS_FAMILY_UNIX
